<?php

namespace app\api\controller;

use app\api\model\Active as ActiveModel;
use app\BaseController;
use app\lib\tool\Str;

class Active extends BaseController
{
    /* 获取 */
    public function getList()
    {
        $cid = input('cid', 0, 'intval');
        $limit = input('limit', 0, 'intval');
        if ($limit) {
            $data = ActiveModel::order('time desc')->limit($limit)->where('cid', $cid)->select();
        } else {
            $page = input('page', 1, 'intval');
            $perpage = 12;
            $data = ActiveModel::order('time desc')->page($page, $perpage)->where('cid', $cid)->select();
        }
        return show(config('status.success'), '获取社区动态列表', $data);
    }

    /* 获取 */
    public function getOne()
    {
        $cid = input('cid', 0, 'intval');
        $id = input('id', 0, 'intval');
        $data = ActiveModel::where(['cid' => $cid, 'id' => $id])->find();
        if ($data) {
            ActiveModel::update(['view' => $data['view'] + 1], ['cid' => $cid, 'id' => $id]);
            $data['view'] = $data['view'] + 1;
            $data['content'] = Str::fontToSpan($data['content']);
        }
        return show(config('status.success'), '获取社区动态详情', $data);
    }
}
